home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_casm / miracle.zip / MIRACLE.TXT < prev    next >
Text File  |  1996-10-02  |  61KB  |  2,686 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.             User Manual
  15.  
  16.  
  17.             Miracle C Compiler
  18.  
  19.  
  20.  
  21.             version 1.6
  22.             3 October 1996
  23.  
  24.  
  25.  
  26.             Copyright 1989-96  bts
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42. The Miracle C Compiler runs on a 386 PC (or better) under MS-
  43. DOS, accepting a dialect of the C language and generating 
  44. object code suitable for Microsoft or compatible linker. 
  45.  
  46. All of traditional (Kernighan & Ritchie) C syntax is 
  47. implemented, including record (struct/union) and enumerated 
  48. data types, int, long and floating point data types, user type 
  49. definition, bit fields in structs, initializers for all data 
  50. types. Both traditional and new (ANSI) function declaration is 
  51. supported. There is a comprehensive library of functions.
  52.  
  53.  
  54.  
  55. Table of Contents
  56.  
  57. REGISTRATION                4
  58. DISCLAIMER                    4
  59. USING THE COMPILER            4
  60. FLOATING POINT SUPPORT        5
  61. ENVIRONMENT VARIABLES        5
  62. COMPILER SWITCHES            5
  63. EXAMPLE PROGRAMS            6
  64. LANGUAGE FEATURES            7
  65. LEXICAL ELEMENTS            7
  66. 1. Operators                7
  67. 2. Separators                7
  68. 3. Identifiers                7
  69. 4. Reserved words            7
  70. 5. Constants                7
  71. PREPROCESSOR                8
  72. Macro substitution            8
  73. File inclusion                9
  74. Conditional Compilation        10
  75. Other Features                11
  76. FUNCTIONS                    11
  77. TYPES                        13
  78. Record (Struct/Union)        14
  79. Typedef                        14
  80. Type Compatibility            15
  81. DECLARATIONS                15
  82. Initializers                18
  83. EXPRESSIONS                    19
  84. STATEMENTS                    21
  85. ASSEMBLER PROGRAMMING INTERFACE    22
  86. FUNCTION LIBRARY            23
  87. STARTUP CODE                23
  88. INCLUDE HEADER FILES        23
  89. LIBRARY FUNCTIONS            23
  90. abs, labs    23
  91. calloc    23
  92. close    24
  93. create    25
  94. exit    25
  95. fclose    25
  96. feof    26
  97. fflush    26
  98. fgetc    27
  99. fgets    27
  100. fopen    28
  101. fprintf    28
  102. fputc    29
  103. fputs    29
  104. fread    30
  105. free    30
  106. fscanf    31
  107. fwrite    31
  108. getc    31
  109. getchar    32
  110. gets    32
  111. is-ctype    33
  112. malloc    33
  113. memchr    34
  114. memcmp    34
  115. memcpy, memmove    34
  116. memset    34
  117. open    35
  118. printf    35
  119. putc    36
  120. putchar    36
  121. puts    37
  122. read    37
  123. scanf    38
  124. sprintf    39
  125. sscanf    39
  126. strcat    39
  127. strchr    40
  128. strcmp    40
  129. strcpy    40
  130. strdup    40
  131. strlen    40
  132. strlwr    41
  133. strncat    41
  134. strncmp    41
  135. strncpy    41
  136. strnicmp    41
  137. strpbrk    42
  138. strrchr    42
  139. strrev    42
  140. strspn    42
  141. strupr    42
  142. tolower, toupper    43
  143. ungetc    43
  144. vsprintf    43
  145. write    44
  146.  
  147.  
  148. REGISTRATION
  149.  
  150. The compiler is shareware, and is supplied  on a trial use 
  151. basis. The compiler package is copyright material and should 
  152. not be modified or disassembled. Programs written using the 
  153. compiler may be freely distributed.
  154.  
  155. If you find it useful you should register. Registration costs 
  156. US$15, Can$20 or GBP10, and entitles you to receive upgrades 
  157. for one year. Payment should be made out to ôMiracle Software 
  158. Technologyö.
  159.  
  160. Registration is from the developer;
  161.  
  162.     Miracle Software Technology
  163.     PO Box 52051
  164.     41 York Street
  165.     Ottawa, Ontario K1N 5S0
  166.     Canada
  167.  
  168. At the time of writing Miracle C is under active development 
  169. by the author, and a further release is planned for winter 
  170. 1996/7. By registering you support further development of the 
  171. compiler. Should you wish to make a direct contribution to a 
  172. future version (for example by writing a compiler utility, 
  173. library functions or source code), please write to the 
  174. developer at the above address.
  175.  
  176. DISCLAIMER
  177.  
  178. The compiler should be regarded as a teaching tool and is 
  179. distributed on the shareware principle, without any warranty, 
  180. without even warranty of merchantability or fitness for a 
  181. particular purpose. No guarantee is made regarding the 
  182. performance of the compiler, and no responsibility can be 
  183. taken for use of, or inability to use, the compiler.
  184.  
  185. It is intended that the next release of Miracle C will have 
  186. compiler source code available on registration, in support of 
  187. the compilerÆs intended role as a teaching support tool.
  188.  
  189. USING THE COMPILER
  190.  
  191. The following files are present in a compressed form in the 
  192. archive;
  193.  
  194. miracle.doc    documentation in MS Word format
  195. miracle.txt    documentation in text format
  196. cc.exe        the C Compiler
  197. ccl.lib        C compiler library
  198. mc.bat        batch file for compiler
  199.  
  200. and several example programs;
  201.  
  202. example.c
  203. hanoi.c
  204. cat.c
  205. sieve.c
  206. maze.c    maze
  207. slr.c    grammar.c
  208.  
  209. Floating point support
  210.  
  211. The compiler requires an 8087 coprocessor (or better), or 
  212. emulation program, to perform floating point arithmetic. Such 
  213. a coprocessor is integrated into the 80486 and subsequent 
  214. CPUs. If your system does not have a numeric coprocessor you 
  215. should obtain a public domain emulation program such as 
  216. em87.com to perform floating point computations.
  217.  
  218. Environment Variables
  219.  
  220. The compiler uses the following environment variables;
  221.  
  222. LIB        directory containing library ccl.lib
  223.         (this is only used by a linker)
  224.  
  225. INCLUDE    directory containing system include files <*.h>
  226.         (if unset, defaults to \cc\include)
  227.  
  228. LINKER    name of linker, eg LINKER=BLINK
  229.         (if unset, defaults to LINK, the Microsoft linker)
  230.  
  231.         Note that a linker is not supplied with the 
  232. compiler.
  233.         Use the Microsoft linker supplied with DOS, or a 
  234. compatible linker.
  235.  
  236.         CC output is Microsoft/Intel object module format, 
  237. as documented
  238.         in the MS-DOS Encyclopedia. The linker must accept 
  239. Microsoft object.
  240.  
  241. Before compiling a program set the environment variables to 
  242. suitable values;
  243.  
  244. C:\> SET LIB=\CC
  245. C:\> SET INCLUDE=\CC\INCLUDE
  246. C:\> SET LINKER=LINK
  247.  
  248. Compile one of the example files;
  249.  
  250. C:\CC> MC EXAMPLE
  251. Microsoft (R) Overlay Linker  Version 3.51
  252. Copyright (C) Microsoft Corp 1983, 1984, 1985, 1986.  All 
  253. rights reserved.
  254.  
  255. C:\CC>
  256.  
  257. This will compile and link `example.c', creating example.obj, 
  258. example.exe.
  259.  
  260. Compiler switches
  261.  
  262.     -j    signed char constants
  263.     -n    noisy compile
  264.     -p    disable autoprototyping
  265.     -r    set error limit
  266.     -s    generate source listing (.src) after preprocessing
  267.     -t    allow trigraphs
  268.     -w    no warnings
  269.  
  270.     -Dname    define macro
  271.     -Uname    undefine macro
  272.     -Iname    add include directory
  273.  
  274.  
  275. Only one program file may be compiled at one time. To compile 
  276. and link together several programs, compile them separately 
  277. with `-c' option, then link them with ccl.lib.
  278.  
  279.  
  280. If the compiler finds an error (in preprocessing, parsing or 
  281. other compilation error, eg an undeclared variable) it will 
  282. print the statement where it occurred and stop if the error 
  283. limit has been reached. Functions should be declared before 
  284. being called, although this is not mandatory. If they are not, 
  285. then auto-prototyping will generate a prototype for a new 
  286. function returning int. A function definition automatically 
  287. declares the function if it has not been declared or auto-
  288. prototyped earlier.
  289.  
  290.  
  291. EXAMPLE PROGRAMS
  292.  
  293. A few example programs are included to illustrate Miracle C 
  294. facilities.
  295.  
  296. example.c    hanoi.c
  297. cat.c        sieve.c
  298. maze.c    maze
  299. slr.c    grammar.c
  300.  
  301.  
  302. example.c    shows most of CC's features; structs/unions; 
  303. initializers for structs and arrays;
  304.         typedefs; function prototyping; functions with local 
  305. variables, and scoping;
  306.         data types; signed and unsigned int, char and long 
  307. variables, floating point;
  308.         use of some library functions for file handling
  309.  
  310. cat.c        reverse words in a sentence, eg `I am here' to 
  311. `here am I'
  312.  
  313. hanoi.c        non-recursive towers of hanoi
  314.         (originally from a Programmer's Challenge in 
  315. Computer Shopper magazine!!)
  316.         gives the sequence of moves to move all discs from 
  317. first to third peg via second
  318.  
  319. sieve.c        Eratosthenes sieve to find prime numbers by 
  320. eliminating composites
  321.         developed from a BYTE C benchmark program
  322.  
  323. maze.c        maze solver, finds shortest path through maze 
  324. from A to B
  325. maze        eg.    C:\> MAZE<MAZE
  326.         uses an algorithm from graph theory to find shortest 
  327. path
  328.  
  329. slr.c        simple parser generator for SLR grammar
  330.         given a grammar file, generates a recognizer program 
  331. to parse the SLR grammar
  332. grammar    grammar file for slr.c
  333.  
  334.  
  335. LANGUAGE FEATURES
  336.  
  337. This is a summary of the C language as implemented by the 
  338. Miracle C compiler.
  339.  
  340. For a tutorial on the C language, read `The C Programming 
  341. Language' by Kernighan and Ritchie. A comprehensive reference 
  342. to the language is the book `C: A Reference Manual' by 
  343. Harbison and Steele, published by Prentice-Hall, which 
  344. describes both traditional and the new ANSI C syntax and 
  345. semantics. Miracle C implements the traditional C language and 
  346. some of the ANSI extensions.
  347.  
  348. Lexical Elements
  349.  
  350. Tokens
  351. The fundamental lexical elements of the language are 
  352. operators, separators, identifiers, reserved-words and 
  353. constants.
  354.  
  355. A C source program consists of tokens separated by whitespace. 
  356. Whitespace is defined as chars 9-13 and 32. Tokens can be 
  357. operators, separators, identifiers, reserved-words or 
  358. constants.
  359.  
  360. 1.    Operators
  361. The following operators are legal in C.
  362.  
  363. ! % ^ & * - + = ~ | < > ' ? += -= *= /= %= <<= >>= &= ^= |=
  364.         -> ++ -- << >> <= >= == != && ||
  365.  
  366. 2.    Separators
  367. Whitespace characters 9-13, and space character 32 are 
  368. separators.
  369. ( ) [ ] { } , ; :
  370.  
  371. 3.    Identifiers
  372. A sequence of any number of letters/digits/underscores 
  373. starting with a letter or underscore character.
  374. Identifiers are case-sensitive so name, Name and NAME are 
  375. different, but external symbols (such as function names) are 
  376. not case-sensitive.
  377.  
  378. 4.    Reserved words
  379. auto break case char default do else enum extern for goto if 
  380. int long register return short signed sizeof static struct 
  381. switch typedef union unsigned void while
  382.  
  383. 5.    Constants
  384. A C constant can be an integer, character or string, or 
  385. floating point constant.
  386.  
  387. integer
  388. An integer can be represented as a decimal, octal (base 8) or 
  389. hexadecimal (base 16) constant.
  390.  
  391. *    decimal (digits)
  392. *    octal 0(digits), eg 0243
  393. *    hex '0x' (or 0X) (hex-digits 0-9 a-f A-F), eg 0x4afb
  394.  
  395. A numeric constant can be unsigned (suffixed by U, eg 56U), 
  396. long (eg 128374L) or floating point.
  397. Floating point constants have syntax  aaa.bbbEeee    where
  398.     aaa.bbb = mantissa
  399.                             eee = exponent (signed, 
  400. optional)
  401.  
  402. character
  403. A character is 'char' or '\esc-char'
  404.     where esc-char= nnn octal literal
  405.             xnn hex literal
  406.  
  407.             a alert        b backspace
  408.             f form feed    n newline
  409.             t tab        r carriage return
  410.             v vertical tab    ' single quote
  411.             ? question mark    " double quote
  412.  
  413. A character constant may contain more than one byte, on which 
  414. case bytes are packed into a word,
  415. for example    int a='xy';
  416.  
  417. string
  418. A string is "string" where the string has printable characters 
  419. or \escaped-characters.
  420. Constant strings are null-terminated, eg sizeof("hello")=6
  421.  
  422.  
  423. Preprocessor
  424.  
  425. The preprocessor performs macro substitution, file inclusion 
  426. and conditional compilation on the source program. Use the `-
  427. s' compiler option to see the program text after 
  428. preprocessing.
  429.  
  430. The preprocessor allows a line to be continued by ending it 
  431. with a `\' character. Tokens and strings can be split across 
  432. lines.
  433.  
  434. Preprocessor directives are lines starting with `#'. A line 
  435. with only '#' is a null directive and is ignored by the 
  436. preprocessor.
  437.  
  438.  
  439. Macro substitution
  440. The #define preprocessor directive defines a macro, optional 
  441. parameter list and associated substitution string. A macro can 
  442. have no parameter list, eg
  443.  
  444.     #define WORD_SIZE 16
  445.  
  446. then every occurrence of WORD_SIZE in the program text is 
  447. replaced with `16'.
  448. The general form of a macro definition allows zero or more 
  449. parameters;
  450.  
  451.     #define <name>(parameters) <replacement text>
  452.  
  453.     #define afunc() otherfunc()
  454.     #define times(x,y) ((x)*(y))
  455.  
  456. every call to afunc() is replaced with a call to otherfunc(); 
  457. when `times' is used, actual arguments are substituted for 
  458. macro parameters in the replacement text, eg
  459.  
  460.  
  461.     times(4,times(5,6))
  462. gives
  463.     ((4)*(((5)*(6))))
  464.  
  465. The number of arguments when the macro is used must match the 
  466. number of parameters when it is declared.
  467.  
  468. A macro definition may be split across more than one line by 
  469. line continuation with \
  470.  
  471.     #define plus(x,y) \
  472.         ((x) + (y))
  473.  
  474. After macro substitution, the line is scanned again so macros 
  475. created by the expansion can be recognized and expanded.
  476.  
  477.  
  478. The following macros are predefined by the preprocessor;
  479.  
  480. MIRACLE    defined as 1
  481.         use for code specific to Miracle C compiler
  482.  
  483. MSDOS        defined as 1
  484.         use for code specific to MS-DOS
  485.  
  486. __FILE__    current source file
  487.  
  488. __LINE__    line in current source file
  489.  
  490. __DATE__    today's date, returned as "Mmm dd yyyy"
  491.  
  492. __TIME__    time of compilation, returned as "hh:mm:ss"
  493.  
  494.  
  495. Redefinition of macros (benign or otherwise) is allowed. No 
  496. warning or error is given if redefinition occurs.
  497.  
  498. A macro definition can be cleared using `#undef' directive;
  499.  
  500.     #undef times
  501.  
  502.  
  503. File inclusion
  504. The `#include' directive allows C source files to be included 
  505. in the program text. When the end of the included file is 
  506. reached, compilation continues from the line after the 
  507. `#include' directive. Include files may be nested; but they 
  508. should including themselves, directly or indirectly, causes 
  509. the compiler to crash. Preprocessor include files usually have 
  510. a .h suffix (header files). There are two forms of #include 
  511. directive;
  512.  
  513.     #include "filename"
  514.  
  515. includes a file in the current directory,
  516.  
  517.     #include <filename>
  518.  
  519. includes a file from the system include directory, which is 
  520. given by the INCLUDE environment variable. If INCLUDE is not 
  521. set, the system include directory defaults to `\cc\include'.
  522.  
  523. The inclusion-file can be specified by a macro;
  524.  
  525.     #define MYINCLUDES "my.h"
  526.     #include MYINCLUDES
  527.  
  528. A complete pathname can be given in the first form of include;
  529.  
  530.     #include "\cc\graphics\graf.h"
  531.  
  532. Conditional Compilation
  533. The preprocessor allows compilation of sections of code to be 
  534. conditional on the values of expressions, using the directives 
  535. `#if' `#ifdef' `#ifndef' `#else' `#endif'. Lines after an 
  536. unsuccessful conditional compilation directive are discarded 
  537. until the next conditional compilation directive.
  538.  
  539. A conditionally compiled section of code starts with #if 
  540. #ifdef or #ifndef and ends with a matching #endif. It may 
  541. contain #else or #elif directives, and other (nested) 
  542. conditionally compiled code sections.
  543.  
  544.  
  545. `#if expr'
  546. If the C expression `expr' evaluates to 1, lines are processed 
  547. until a matching else, elif or endif is found. If it evaluates 
  548. to 0, following lines of code are discarded until a matching 
  549. else, elif or endif is found. The expression `expr' must be a 
  550. constant recognisable to the preprocessor, containing macro, 
  551. character and number constant values only.
  552.  
  553.  
  554. `#ifdef name'  `#ifndef name'
  555. If the macro `name' is defined (ifdef) or undefined (ifndef), 
  556. lines are processed until a matching else, elif or endif is 
  557. found. Otherwise, following lines of code are discarded until 
  558. a matching else, elif or endif is found.
  559.  
  560. `#else'
  561. The else directive follows an if, ifdef or ifndef, or can 
  562. follow #elif directives. Lines of code following #else are 
  563. processed only if preceeding lines were not processed.
  564.  
  565. `#elif'
  566. This is a switch/case construct for conditional compilation;
  567.  
  568.     #if expr1
  569.     ...
  570.     #elif expr2
  571.     ...
  572.     #elif expr3
  573.     (etc)
  574.     #else
  575.     ...
  576.     #endif
  577.  
  578. `#endif'
  579. terminates a conditionally compiled code section.
  580.  
  581.  
  582. Other Features
  583. The #error directive aborts compilation with an error message;
  584.  
  585.     #ifdef x_once
  586.     #error Illegal include recursion
  587.     #endif
  588.     #define x_once
  589.  
  590. detects a program's attempt to include itself; implement 
  591. "once-only" inclusion of header files similarly.
  592.  
  593.  
  594. Stringification converts a token into a string, and is useful 
  595. when debugging a program;
  596.  
  597.     #define fatal(tok1,tok2) printf("bad tokens: 
  598. %s;%s;",#tok1,#tok2)
  599.  
  600. Concatenation of adjacent strings is supported by Miracle C 
  601. compiler,
  602. so
  603.     #define fatal(tok1,tok2) printf("bad tokens: " #tok1 ";" 
  604. #tok2)
  605. is allowed.
  606.  
  607.  
  608. Token merging using the ## operator creates a single token 
  609. from two or more
  610. tokens in a macro definition;
  611.  
  612.     #define line(i) line ## i
  613.  
  614. then    line(1) == line(2)
  615. becomes    line1 == line2
  616.  
  617.  
  618. Functions
  619.  
  620. Miracle C supports a both the traditional syntax for function 
  621. definition, and a syntax similar to ANSI C for function 
  622. prototyping. Functions can be declared and prototyped before 
  623. use. The traditional way of introducing functions, eg.
  624.  
  625.     int main(argc,argv) int argc; char **argv;
  626.  
  627. is supported. Traditionally, functions weren't declared before 
  628. use or definition; CC allows functions to be declared and 
  629. prototyped before use, zero times or exactly once, or a parse 
  630. error results. Note that 'parse errors' occur when the current 
  631. symbol is not one of the expected legal symbols, hence a 
  632. function redeclaration may generate a parse error.
  633.  
  634. CC's function declaration syntax is similar to ANSI, eg
  635.  
  636.     void afunc(int one, char *b);
  637.  
  638. but the ANSI syntax
  639.  
  640.     void afunc(int, char *);
  641.  
  642. is not supported (yet). The number and type of parameters, and 
  643. return value, in a function definition must match exactly that 
  644. of the function declaration. Miracle CC supports declaration 
  645. of functions with a variable number of parameters, eg
  646.  
  647.     int printf(char *fmt, ...);
  648.  
  649. but their definition is not supported (yet).
  650.  
  651. Miracle C has the concept of `function types' which are
  652.  
  653.     type1 x .. x typen x varargs -> typer
  654.  
  655. for a function taking n parameters of type (type1, ..., typen) 
  656. and returning a result of type typer, with a variable number 
  657. of arguments if varargs set.
  658.  
  659. A pointer to a function is assigned a function type, which 
  660. should match the type of a function assigned to it; for 
  661. example,
  662.  
  663.     void (*fptr)();
  664.     int printf(char *fmt, ...);
  665.  
  666.     (fptr=&printf,*fptr)("hello");
  667.  
  668. will fail with the error message
  669.  
  670. 158: wrong # args in function call
  671.  
  672. '(fptr=&printf,*fptr)("hello")'
  673.  
  674.  
  675. Functions may return signed or unsigned int, char or long 
  676. values, but not struct or union. They may return pointers to 
  677. any item (including struct), or a user defined type, as long 
  678. as that type isn't a struct. Nor can a function return an 
  679. array, or another function.
  680.  
  681. Parameters in a function call are pushed on the stack using 
  682. normal C linkage conventions, ie right-to-left, to allow for 
  683. functions with a variable number of parameters (eg printf, 
  684. first argument specifies number and type of subsequent). 
  685. Parameters should be word entities, ie int char and pointer 
  686. type.
  687.  
  688. Functions may be declared as extern, static or register, but 
  689. these classes are ignored by the compiler. Miracle C marks 
  690. functions defined in the program text as `internal' and others 
  691. as `external' and generates object accordingly. Static 
  692. functions (visible only within a program) are not supported 
  693. (yet!).
  694.  
  695. Miracle C needs functions with no parameters to be declared by
  696.  
  697.     int afunc();
  698.  
  699. It does not follow the ANSI convention of declaring such as 
  700. function by
  701.  
  702.     int afunc(void);
  703.  
  704. nor does it follow the traditional C convention of declaring a 
  705. function's return type, but omitting a declaration of 
  706. parameters, using the above syntax.
  707.  
  708. Parameters in a definition count as local variables in the 
  709. highest level block in the function body, following the ANSI 
  710. definition.
  711.  
  712. Storage classes are not allowed for parameters in a 
  713. definition. Functions with return type `void' must not return 
  714. a value.
  715.  
  716. A function declared to have return type `int' need not specify 
  717. return type in the function definition, so we allow
  718.  
  719.     int main();
  720.     ....
  721.     main() { ... }
  722.  
  723. Function prototypes may not be nested;
  724.  
  725.    void (*signal(int sig, void (*func)(int sig)))(int sig);
  726.  
  727. is illegal, but can circumvent this by
  728.  
  729.    typedef void sig_handler(int sig);
  730.    sig_handler *signal(int sig,sig_handler *func);
  731.  
  732.  
  733. Autoprototyping of functions is allowed. If a function call is 
  734. introduced for a function which has not been declared, a 
  735. declaration is automatically generated for the function. The 
  736. automatically generated prototype will use the types of 
  737. parameters which are given to the function on call, and will 
  738. assume a function return type of int. If the desired function 
  739. type is different to that which will be implicitly generated 
  740. from the function call then an explicit declaration should be 
  741. made before the function is called. Function autoprototyping 
  742. may be disabled by a compiler flag.
  743.  
  744.  
  745. Types
  746.  
  747. Miracle C supports void, scalars (pointers, signed and 
  748. unsigned char int long), enumeration types, floating point 
  749. types, pointers to any object, struct/union and multi-
  750. dimensional array types. It also has `function types' (see the 
  751. section on functions).
  752.  
  753. As a small-model 8086 compiler, CC supports 16-bit ints and 
  754. pointers, 8 bit char values (expanded to 16 bits when passed 
  755. as parameters on the stack), and 32 bit longs. The type 
  756. `short' is a synonym for `int'. An object declared by
  757.  
  758.     signed avar;
  759.  
  760. is a signed integer. Floating point numbers are not 
  761. implemented. Long integers are not completely implemented; for 
  762. example, adding a long to an int is not allowed, but adding 
  763. two longs is (so cast the int to long before adding); and long 
  764. values should not be passed as function arguments.
  765.  
  766. Miracle C maintains a type value for each expression, computed 
  767. from the types of its components; a data size is associated 
  768. with each type value.Traditional C casts are allowed, but type 
  769. checking of assignments etc is not strict.
  770.  
  771. Array subscripts, and adding an int to a pointer, is scaled up 
  772. according to the data size of the type being pointed to, eg if 
  773. intptr is int * then intptr+1 (or intptr[1]) will point to 
  774. intptr plus 2 in memory.
  775.  
  776. Arrays of any type except void can be declared and can be 
  777. multi-dimensional. Void variables are not allowed.
  778.  
  779. Enumerations are introduced by an `enum' declaration, such as
  780.  
  781.     enum colour { red, green, blue } mycolour;
  782.     enum colour anothercolour.
  783.  
  784. The tag (here `colour') is optional, and can be used in a 
  785. later declaration. Enumerations must start at zero, the 
  786. traditional "red=2" syntax is not supported. An enum variable 
  787. is int. The enum namespace is separate from others, hence
  788.     enum one { one, two } number;
  789.  
  790. is allowed.
  791.  
  792.  
  793. Record (Struct/Union)
  794.  
  795. Structure (record) type is a collection of named components;
  796.  
  797.     struct structag
  798.         {
  799.         int x, y[3];
  800.         char z;
  801.         struct structag *sptr, *tptr;
  802.         }
  803.         sarray[10], *sptr;
  804.  
  805.     struct structag another, *anotherptrs[5];
  806.  
  807. Structure tag `structag' identifies this structure type for 
  808. other declarations. The struct has components x,y,z and two 
  809. pointers to other `structag' structs (so we've declared a tree 
  810. structure type). Structure declarations cannot be nested (that 
  811. would be infinitely silly). Structure component names live in 
  812. a separate namespace for each struct/union type, hence we can 
  813. introduce variables with the same name. Struct components 
  814. occupy successive memory locations, and the size of a struct 
  815. (as given by sizeof) is the sum of the sizes of it's 
  816. components.
  817.  
  818. Struct components are referred to using . and -> operators. In 
  819. the example above we declare sarray an array of 10 `structag' 
  820. structs and allocate space for it (either static or on the 
  821. stack). Direct reference by sarray[i].y[0], indirect reference 
  822. via pointer to struct by sptr->z, sptr->tptr->y[i].
  823.  
  824. A union is declared using the same syntax as struct, but 
  825. contains only one of its members at any one time (so the size 
  826. of a union is the max of the size of it's components, and all 
  827. items are at offset zero in the union).
  828.  
  829. Nested structs/unions are allowed. Bit fields in structs 
  830. aren't implemented.
  831.  
  832. Struct bitfields are permitted. A single bitfield must not 
  833. exceed the capacity of a machine word (16 bits). All the 
  834. normal arithmetic operations and assignment are permitted on 
  835. bitfields, as are struct bitfield initializers.
  836.  
  837. Typedef
  838.  
  839. User defined type synonyms are introduced by the `typedef' 
  840. statement;
  841.  
  842.     typedef int *ptr, (*func)(), afun();
  843.     ptr wordptr;
  844.     afun main;
  845.     func funcptr=main;
  846.  
  847.     ptr    `ptr to int'
  848.     func    `ptr to function: void->int'
  849.     afun    `function: void->int'
  850.  
  851. Typedef doesn't create a new type, only type synonyms, so type 
  852. compatibility/comparison works. Typedef for function can 
  853. include function prototypes;
  854.  
  855.     typedef int funci(char *x);
  856.     funci funky;
  857.  
  858. A typedef name may be global, or local to a function. The ANSI 
  859. standard allows typedefs to be redeclared in a block, but CC 
  860. doesn't (yet).
  861.  
  862. Type Compatibility
  863.  
  864. Two expressions are assignment compatible  t1=t2  if t1 is an 
  865. lvalue, and;
  866.  
  867.     - t1 is (u)long, t2 is (u)int/char, extended to 32 bits
  868.     - t1 is (u)int/char, t2 is (u)long, truncated to 16 bits
  869.     - t1 and t2 are both (u)long, 32 bit assignment
  870.     - t1 is (u)char, 8 bit assignment
  871.  
  872.     else 16 bit assignment (of int, pointer etc)
  873.  
  874. Bitfields may be signed or unsigned integer quantities and 
  875. have the same type compatibility rules as integers.
  876.  
  877. Some operators eg  || && ^ | & * / %  require (u)int operands.
  878. Pointers may be subtracted (t1-t2 yields a pointer of type t1) 
  879. but not added (addition of pointer is meaningless).
  880.  
  881. Array types count as ptrs, depth of ptr=dimensionality of 
  882. array.
  883. Struct/unions types are compatible if they have the same 
  884. struct tag.
  885.  
  886.  
  887. Declarations
  888.  
  889. Variables, functions and user defined data types are 
  890. introduced by declaration statements. A declarator gives 
  891. identifier name and type;
  892.  
  893. Scalar        int x
  894. Floating point    double x;
  895. Pointer        int *x; char *y[];        (y is pointer to 
  896. array, same as char **y;)
  897. Array        int (*x)[4];            (x is pointer to array 
  898. of 4 ints)
  899. Function    int x(), y(int a,char *b), (*x[])(int a);
  900.  
  901. To parse a declaration, start from name and work out according 
  902. to precedence rules;
  903.  
  904.     int *a[10]            a is array of 10 ptrs to int
  905.     int (*x[])(int a)        x is array of ptrs to functions: 
  906. int->int
  907.  
  908.  
  909. Global variables are visible throughout the program from the 
  910. point of declaration, unless they are hidden by a local 
  911. declaration with the same name. Local variables are visible 
  912. throughout the block in which they are defined, unless they 
  913. are hidden by a declaration at an inner level with the same 
  914. name. Globals are extern by default.
  915.  
  916. Static variables (globals and local statics) have storage 
  917. allocated at compile time in static data area to hold a 
  918. possible initializer. Local variables are allocated on the 
  919. stack at runtime and are local to a block, or are function 
  920. parameters.
  921.  
  922. Parameters to a function are considered as being declared at 
  923. the topmost local level in the function, so a local 
  924. declaration using a parameter name is an error. Local objects 
  925. may not be declared more than once.
  926.  
  927. All floating point types (float, double and long double) are 
  928. treated internally as 8-byte double quantities. Normal 
  929. floating point arithmetic is allowed on these quantities. No 
  930. support for numeric coprocessing is included in this version.
  931.  
  932. Initializers are allowed for both global and local objects and 
  933. follow traditional syntax. Global initializers are evaluated 
  934. at compile-time, a constant is stored in the static data 
  935. segment. Therefore, expressions in global initializers can 
  936. only contain things which can be evaluated at compile-time, 
  937. such as constants and address of objects.
  938.  
  939. Local initializers are evaluated when a function is called, so 
  940. expressions may (even) contain function calls.
  941.  
  942. Multi-dimensional arrays, structs/unions, arrays of structs 
  943. and initializers for them are supported using traditional C 
  944. syntax.
  945.  
  946. A struct tag can be declared before any variables are;
  947.  
  948.     struct S { int a, b; };
  949.     struct S fred;
  950.  
  951. A struct can be declared without tag or variables;
  952.  
  953.     struct { int a,b; };
  954.  
  955. is allowed but pointless.
  956.  
  957. Also  static struct S { int a,b; }; is allowed but `static' is 
  958. meaningless.
  959.  
  960.  
  961. A global variable may be declared more than once, but all 
  962. declarations must agree on type. A local variable may only be 
  963. declared once. Global arrays must have the same dimensions 
  964. when redeclared, but the first dimension need not be 
  965. specified;
  966.  
  967.     char uu[5][4][3]; char uu[][4][3];
  968.  
  969. Only one definition may exist for a variable, so a global may 
  970. have only one declaration with an initializer. Redeclaration 
  971. of functions is not supported.
  972.  
  973. Type definitions, structs/unions and enumerated types are 
  974. supported; see the section on `types'.
  975.  
  976. Global variables are allocated in a static data area. 
  977. Uninitialized globals are set to zero; uninitialized parts of 
  978. partly initialized globals are zeroed. Initialized globals 
  979. give PUBDEF records for the linker, uninitialized globals give 
  980. COMDEF records.
  981.  
  982. Arrays are allocated at compile-time (static) or run-time 
  983. (auto), hence  static char p1[]="hello"  allocated 6 bytes and 
  984. copies "hello" into it, but pointer initialization is to run-
  985. time objects, hence  char *p2="hello" allocates 2 bytes for p2 
  986. and points it to a static string item.
  987.  
  988. Statement labels are local to a function body, and the target 
  989. of goto statements
  990.  
  991.     here:
  992.         ...
  993.         goto here;
  994.  
  995. Forward references are allowed if;
  996.  
  997.     - statement label may be used by goto before it is 
  998. declared
  999.  
  1000.     - an identifier should be visible immediately after 
  1001. declaration,
  1002.       eg int fred=sizeof(fred)
  1003.       but this is not yet implemented
  1004.  
  1005.     - struct can contain pointer to instance of itself
  1006.  
  1007.     - function declaration and use before definition
  1008.  
  1009.  
  1010.  
  1011. Overloading of identifiers permits an identifier to have 
  1012. different meanings depending on context;
  1013.  
  1014.     - macro names are defined and used by the preprocessor
  1015.  
  1016.     - struct tag names have a separate name space
  1017.  
  1018.     - enum tag names have a separate name space
  1019.  
  1020.     - typedef, enum and label names are checked before 
  1021. variable names.
  1022.       a compile error results if a variable is declared with 
  1023. the same
  1024.       name as a typedef or enum name, or goto-label
  1025.  
  1026.     - struct component names are specific to a struct/union 
  1027. type,
  1028.       so two structs can have components of the same name
  1029.  
  1030.  
  1031.  
  1032. External names must be defined at top-level (global 
  1033. variables). Extern declarations inside functions are not 
  1034. supported and are treated as declarations of internal 
  1035. variables. Global variables are defined to the linker and 
  1036. accessible to other programs.
  1037.  
  1038. The storage classes auto and register are ignored by the 
  1039. compiler. Static variables local to a function are allocated 
  1040. in the static data area, and should have constant 
  1041. initializers.
  1042.  
  1043.  
  1044.  
  1045.  
  1046. Initializers
  1047. The compiler allows initialization of scalars, strings, 
  1048. struct/unions and arrays. An initializer sets the initial 
  1049. value of a variable, at compile time for static objects 
  1050. (globals or local statics) or run time for automatic 
  1051. variables. If no initializer exists for a global variable, 
  1052. it's set to zero; if none exists for a local, it's initial 
  1053. value is unpredictable.
  1054.  
  1055. The traditional C syntax for initializers is supported;
  1056.  
  1057.     int x=4;
  1058.  
  1059.     struct { int a; char *s; int b; } icky = { 1, "astr", 2 
  1060. };
  1061.  
  1062.     enum { red, blue } colour = blue;
  1063.  
  1064. Union initializer is for the first component of the union. 
  1065. Structs and multi-dimensional arrays are initialized 
  1066. recursively;
  1067.  
  1068. int m1[2][3] = { { 1, 2, 3 }, { 4, 5, 6 } };
  1069.  
  1070. The `shape' of an initializer (brace structure) must match 
  1071. that of the object being initialized. If there aren't enough 
  1072. initializing items for an array or struct initializer, the 
  1073. rest of the object is zeroed. If there are too many, a compile 
  1074. time error results.
  1075.  
  1076. If the outermost dimension of an array is unspecified, it's 
  1077. taken from the initializer;
  1078.  
  1079.     char a[] = { 'a', 'b', 'c', '\0' }, *b="hello";
  1080.  
  1081. Braces can be dropped in the initializer;
  1082.  
  1083.     int a[2][3]={1,2,3,4,5,6};
  1084.  
  1085. the number of items in the initializer must not exceed the 
  1086. declared object.
  1087.  
  1088. Static variable initializer expressions contain only objects 
  1089. which can be evaluated at compile-time, ie constants and 
  1090. addresses of static objects. The address of a global variable 
  1091. cannot be found if it is declared but not defined;
  1092.  
  1093.     int a, *b=&a;
  1094.  
  1095. won't compile, but
  1096.  
  1097.     int a=2, *b=&a;
  1098.  
  1099. is allowed.
  1100.  
  1101. Local variable initializer expressions are evaluated at 
  1102. runtime, when a function is called. They can contain any 
  1103. expression (even function calls). If goto jumps to a label in 
  1104. a block, initializers for that block don't run.
  1105.  
  1106. Initializers are permitted for floating point variables, and 
  1107. bitfields in struct (record) types, using the standard C 
  1108. syntax.
  1109.  
  1110.  
  1111. Expressions
  1112.  
  1113. An expression consists of operators acting on other 
  1114. expressions, or base values (variables or constants). An 
  1115. expression is either an lvalue or an rvalue; an lvalue refers 
  1116. to an object in memory, eg a variable; an rvalue is a non-
  1117. lvalue.
  1118.  
  1119. Lvalues can be `variable'  e[k]  lvalue.name  e->name  *e
  1120. they are used by  &  ++  --  assignment-operators
  1121.  
  1122.  
  1123. Expressions are formed from operators, in precedence order:
  1124.  
  1125. ,    sequential evaluation, yields second operand
  1126.  
  1127. =   +=    -=  *=     /=   %=
  1128. &=  |=    ^=  >>=  <<=  assignment
  1129.  
  1130.     assign    (u)long = (u)(int|char)
  1131.         (u)long = (u)long
  1132.         (u)(int|char) = (u)long
  1133.         word/byte lvalue = word/byte rvalue
  1134.  
  1135. ?:    conditional   exp1 ? exp2 : exp3
  1136.     depending on value of exp1, yields exp2 or exp3
  1137.     type of exp1 must be int
  1138.     types of exp2 and exp3 must match, and must be byte or 
  1139. word
  1140.  
  1141. ||    logical or    exp1 || exp2    only evaluate exp2 if exp1 
  1142. false
  1143.  
  1144. &&    logical and    exp1 || exp2    only evaluate exp2 if exp1 
  1145. true
  1146.  
  1147. |    bit or
  1148. ^    bit xor
  1149. &    bit and
  1150.     bit or, xor, and take (u)int operands and yield (u)int 
  1151. result
  1152.  
  1153. == !=    compare, signed or unsigned
  1154. < >    signed if at least one operand is signed, both are int or 
  1155. char
  1156. <= >=    unsigned if both operands are unsigned int or char, 
  1157. or pointers
  1158.  
  1159.  
  1160. << >>    shift, arithmetic for signed, logical for unsigned
  1161.  
  1162. + -    add sub
  1163.     (u)(char|int), (u)(char|int)
  1164.     ptr, (u)(char|int)    scale up by size of object pointed to
  1165.     (u)long, (u)long
  1166.     can subtract two pointers giving an integer
  1167.  
  1168. * / %    mul div rem
  1169.     take (u)int operands, yield (u)int result
  1170.  
  1171. (type)    cast
  1172.     cannot cast to/from structs/voids
  1173.     cannot cast between chr and ptr, but can between int and 
  1174. ptr
  1175.     if casting long->int then lose high word, int->long high 
  1176. word zero
  1177.  
  1178. *    indirection
  1179.  
  1180. &    address of
  1181.  
  1182. -    unary minus
  1183.  
  1184. !    logical not
  1185.  
  1186. ~    bit not
  1187.  
  1188. sizeof    sizeof(typename)        size of type
  1189.     sizeof("string")        size of constant string + 1
  1190.     sizeof(array-expr)    size of array in bytes
  1191.     sizeof(expr)        sizeof type of expr
  1192.  
  1193. ++ --    post/pre decr/incr
  1194.     if pointer, scaled up by size of object pointed to
  1195.  
  1196. ->    indirect selection by pointer (struct/union member or 
  1197. bitfield)
  1198.  
  1199. .    direct selection (struct/union member or bitfield)
  1200.  
  1201. f(..)    function call, where f is a function designator
  1202.     f has function type and identifies a function
  1203.  
  1204. (expr)    brackets
  1205.  
  1206. a[k]    array subscript; type of k = (u)(int|char)
  1207.     the result of an array subscript is an lvalue only if a 
  1208. is a pointer, or we have reached the last
  1209.     array dimension
  1210.  
  1211.     for example, if  int a[3][2];  then  a[1]=4;  is 
  1212. meaningless and is flagged as an error
  1213.     but this means that
  1214.  
  1215.         int a[2][3], **x;
  1216.         x=&a[1];
  1217.  
  1218.     will not compile. The ANSI solution (`modifiable 
  1219. lvalues') is not implemented.
  1220.  
  1221. number    constant
  1222.  
  1223. string    constant
  1224.  
  1225. variable global, local, lstatic
  1226.  
  1227. Initializer constant expressions are arithmetic constant 
  1228. expressions and address constant expressions (not fully 
  1229. implemented in CC). These can have normal operators & casts, 
  1230. which are evaluated at compile-time.
  1231.  
  1232.  
  1233. Statements
  1234.  
  1235. All traditional C statements are implemented, except for 
  1236. `continue'.
  1237. A statement can be one of the following;
  1238.  
  1239. expr    expression; (discarded)
  1240.  
  1241. null    null statement (actually a null expression)
  1242.  
  1243. label    label: stmt;
  1244.     which can be a goto-label, case-label, or default-label 
  1245. in switch
  1246.  
  1247. goto    goto name;
  1248.     where `name' is a goto-label defined somewhere in 
  1249. function
  1250.  
  1251. block    { decl-list; stmt; ... stmt; }
  1252.     A block starts with zero or more declarations, and 
  1253. contains zero or more statements. Blocks
  1254.      may be nested. Names declared within the block hide 
  1255. declarations of the same name outside
  1256.     the block, and are visible throughout the block unless 
  1257. hidden by a declaration at an inner
  1258.     level.
  1259.  
  1260.     Goto a label inside a block jumps past local variable 
  1261. allocation and initialization code; but
  1262.     the locals are de-allocated at end of block anyway, so 
  1263. don't jump into a block!
  1264.  
  1265. if    if (expr) stmt
  1266.     if (expr) stmt1 else stmt2    NB else belongs to nearest 
  1267. if
  1268.  
  1269.     if `expr' evaluates to non-zero, do stmt1 (else do stmt2)
  1270.     `else' belongs to the nearest `if'
  1271.  
  1272. while    while (expr) stmt
  1273.     continue executing `stmt' while `expr' evaluates to non-
  1274. zero
  1275.  
  1276. do    do stmt while(expr)
  1277.     do `stmt' at least once, then while `expr' evaluates to 
  1278. non-zero
  1279.  
  1280.  
  1281. for    for(expr1; expr2; expr3) stmt        each of exp1,2,3 
  1282. optional
  1283.     expr1= evaluated once at start of loop
  1284.     expr2= continuation condition, tested before stmt 
  1285. executed
  1286.     expr3= iteration expression, evaluated after statement
  1287.  
  1288.     if expr2 omitted then it defaults to true
  1289.     eg.  for(;;) is an infinite loop
  1290.  
  1291.  
  1292. switch    switch(expr)
  1293.        {
  1294.        case n1: ...;
  1295.        case n2: ...;
  1296.          ...
  1297.        default: ...;
  1298.        }
  1299.  
  1300.     case labels must be numbers or char literals;
  1301.     case labels should not be duplicated, at most one default 
  1302. exists;
  1303.     when a case or default is chosen, execution continues 
  1304. until
  1305.     break or end of block
  1306.  
  1307. break    terminate smallest enclosing  while. do, for, switch
  1308.  
  1309. continue continue smallest enclosing  while. do, for
  1310.  
  1311. return    return opt-expr        return from function with 
  1312. optional value
  1313.     void functions must not return a value
  1314.  
  1315.  
  1316.  
  1317. ASSEMBLER PROGRAMMING INTERFACE
  1318.  
  1319. Miracle C functions can call, and be called by, assembler 
  1320. routines.
  1321.  
  1322. Function call is by pushing arguments onto the stack in right 
  1323. to left order,
  1324. and call (pushes ip on stack). The called function pushes bp 
  1325. and allocate
  1326. stack space for local variables. Function return is the 
  1327. reverse; deallocate
  1328. local variables, pop bp, return; caller pops arguments.
  1329.  
  1330.         +-------+
  1331.         | arg n |
  1332.         |   .   |
  1333.         |   .   |
  1334.         | arg 1 |
  1335.         |  ip   |
  1336.         |  bp   |
  1337.         | local |
  1338.         |   .   |
  1339.         |   .   |
  1340.         | local |
  1341.         +-------+
  1342.  
  1343. At entry to a C function, SP points to the return value of IP 
  1344. on the stack.
  1345. To access word arguments;
  1346.  
  1347.         push    bp
  1348.         mov    bp,sp
  1349.         mov    AX,[bp+2]    ; first argument
  1350.         mov    BX,[bp+4]    ; second argument
  1351.         ...
  1352.         pop    bp
  1353.         mov    ax,retvalue    ; return value
  1354.         ret
  1355.  
  1356.  
  1357.  
  1358. FUNCTION LIBRARY
  1359.  
  1360. Startup code
  1361.  
  1362. The startup code initializes segment registers, sets argc/argv 
  1363. parameters
  1364. to zero, and calls function `main'. If `main' returns to the 
  1365. startup routine,
  1366. an exit handler is called which closes files and terminates.
  1367.  
  1368.  
  1369.  
  1370. Include header files
  1371.  
  1372. The following header files are supplied with the compiler in 
  1373. the 'include' subdirectory.
  1374.  
  1375. ctype.h        Prototypes for alphanumeric test and conversion 
  1376. functions.
  1377. io.h        Prototypes for elementary file functions.
  1378. stdio.h        Prototypes for higher level file handling and 
  1379. input/output functions.
  1380. string.h        Prototypes for memory and string handling 
  1381. functions.
  1382. system.h    Prototypes for memory and other functions.
  1383.  
  1384.  
  1385.  
  1386. Library Functions
  1387.  
  1388. The Miracle C library contains functions for string handling, 
  1389. file operations, input/output formatting, memory allocation 
  1390. and other functions.
  1391.  
  1392.  
  1393.  
  1394. abs, labs
  1395.  
  1396.     #include <system.h>
  1397.  
  1398.     int abs(int i)
  1399.     long labs(long i)
  1400.  
  1401.  
  1402.     Produces the absolute (positive or zero) value of its 
  1403. argument.
  1404.     abs takes an int argument returning an int, labs takes a 
  1405. long argument and returns a long.
  1406.  
  1407.  
  1408.  
  1409. calloc
  1410.  
  1411.     #include <system.h>
  1412.  
  1413.     void *calloc(int nitems, int itemsize)
  1414.  
  1415.     Allocates a block of memory that ia nitems * itemsize 
  1416. bytes in size from the heap. The
  1417.     initial contents of the block is zeroed.
  1418.     If not enough memory is available to satisfy the request 
  1419. a null pointer is returned. Since the
  1420.     compiler uses the small memory model, memory requests 
  1421. should be made accordingly.
  1422.     Allocated memory should be freed explicitly when it is no 
  1423. longer required.
  1424.  
  1425.  
  1426.     Example
  1427.  
  1428.     #include <system.h>
  1429.     #include <stdio.h>
  1430.  
  1431.     void main()
  1432.     {
  1433.         char **buffer;
  1434.         int nitems=100;
  1435.  
  1436.         buffer = calloc(nitems,sizeof(char *));    /* allocate 
  1437. 50 pointers to char */
  1438.         if(buffer==NULL)
  1439.             {
  1440.                 printf("out of memory\n");
  1441.                 exit(1);
  1442.             }
  1443.         printf("calloc allocated %d items of %d at : 
  1444. %x\n",nitems,sizeof(char *),buffer);
  1445.         free(buffer);
  1446.         return;
  1447.     }
  1448.  
  1449.  
  1450.  
  1451. close
  1452.  
  1453.     #include <io.h>
  1454.  
  1455.     int close(int fd)
  1456.  
  1457.     Close the file given by file descriptor handle `fd' 
  1458. freeing the file descriptor for use by
  1459.     another file.
  1460.     close does not write an eof character 26.
  1461.     Returns 0 if successful, otherwise -1 if failed.
  1462.  
  1463.  
  1464.     Example
  1465.  
  1466.     #include <io.h>
  1467.     #include <stdio.h>
  1468.     #include <system.h>
  1469.  
  1470.     void main()
  1471.     {
  1472.     int fd;
  1473.         if((fd = open("tfile",O_RDONLY))<0)
  1474.             {
  1475.                 printf("failed to open tfile\n");
  1476.                 exit(1);
  1477.             }
  1478.         printf("close code %d\n",close(fd));
  1479.         return;
  1480.     }
  1481.  
  1482.  
  1483.  
  1484. create
  1485.  
  1486.     #include <io.h>
  1487.  
  1488.     int create(char *fname)
  1489.  
  1490.     Create a file with name `fname'.
  1491.     If successful, returns a file descriptor for the newly 
  1492. created file. Otherwise returns -1 if
  1493.     unsuccessful.
  1494.  
  1495.  
  1496.     Example
  1497.  
  1498.     #include <io.h>
  1499.     #include <stdio.h>
  1500.  
  1501.     void main()
  1502.     {
  1503.         int n;
  1504.         n = create ("tfile");
  1505.         if (n == -1) {
  1506.             printf("Cannot create tfile\n");
  1507.         }
  1508.         return;
  1509.     }
  1510.  
  1511.  
  1512.  
  1513. exit
  1514.  
  1515.     #include <system.h>
  1516.  
  1517.     void exit(int code)
  1518.  
  1519.     Closes files, flushes all output buffers and terminates 
  1520. with return code `code'.
  1521.  
  1522.     Example
  1523.  
  1524.     #include <io.h>
  1525.     #include <stdio.h>
  1526.     #include <system.h>
  1527.  
  1528.     void main()
  1529.     {
  1530.         int n;
  1531.         n = create ("tfile");
  1532.         if (n == -1) {
  1533.             printf("Cannot create tfile\n");
  1534.             exit(1);
  1535.         }
  1536.         exit(0);
  1537.     }
  1538.  
  1539.  
  1540.  
  1541. fclose
  1542.  
  1543.     #include <stdio.h>
  1544.  
  1545.     int fclose(FILE *fp)
  1546.  
  1547.     Close an open file, and flush output buffer for the file. 
  1548. Returns 0 if successful, EOF if not.
  1549.  
  1550.     Example
  1551.  
  1552.     #include <io.h>
  1553.     #include <stdio.h>
  1554.  
  1555.     void main()
  1556.     {
  1557.         FILE *fp;
  1558.         if((fp = fopen("tfile","r"))==NULL) {
  1559.             printf("failed to open file tfile\n");
  1560.             return;
  1561.         }
  1562.         else {
  1563.                 fclose(fp);
  1564.                 printf("closed file tfile\n");
  1565.             }
  1566.         return;
  1567.     }
  1568.  
  1569. feof
  1570.  
  1571.     #include <stdio.h>
  1572.  
  1573.     int feof(FILE *fp)
  1574.  
  1575.     Tests end of file condition for file fp. Returns non-zero 
  1576. if end of file.
  1577.     After an EOF condition no further reads should be 
  1578. performed.
  1579.  
  1580.     Example
  1581.  
  1582.     #include <io.h>
  1583.     #include <stdio.h>
  1584.  
  1585.     void main()
  1586.     {
  1587.         FILE *fp;
  1588.         char buffer[100];
  1589.  
  1590.         fp = fopen ("tfile", "r");
  1591.  
  1592.         while ( !feof(fp) )
  1593.         fgets(buffer, 100, fp);
  1594.  
  1595.         return;
  1596.     }
  1597.  
  1598.  
  1599.  
  1600. fflush
  1601.  
  1602.     #include <stdio.h>
  1603.  
  1604.     int fflush(FILE *fp)
  1605.  
  1606.     Flush buffer for an output file. If the file is open for 
  1607. writing the output buffer is wriiten to
  1608.     disk. If it is open for reading the buffer is cleared and 
  1609. another read operation is forced
  1610.     to occur.
  1611.  
  1612.     Returns 0 is operation successful, otherwise EOF if an 
  1613. error occurred.
  1614.  
  1615.     Example
  1616.  
  1617.     #include <stdio.h>
  1618.     #include <system.h>
  1619.  
  1620.     void main()
  1621.     {
  1622.         FILE *fp;
  1623.  
  1624.         if((fp = fopen("tfile","w"))==NULL)
  1625.              exit(1);
  1626.  
  1627.         fflush(fp);
  1628.     }
  1629.  
  1630.  
  1631.  
  1632. fgetc
  1633.  
  1634.     #include <stdio.h>
  1635.  
  1636.     int fgetc(FILE *fp)
  1637.  
  1638.     Reads and returns a character from a file. Returns next 
  1639. character or EOF.
  1640.  
  1641.  
  1642.     Example
  1643.  
  1644.     #include <stdio.h>
  1645.  
  1646.     void main()
  1647.     {
  1648.         FILE *fp;
  1649.  
  1650.         fp = fopen ("tfile", "r");
  1651.  
  1652.          while ( !feof(fp) )
  1653.         putchar(fgetc(fp));
  1654.  
  1655.         return;
  1656.     }
  1657.  
  1658.  
  1659.  
  1660. fgets
  1661.  
  1662.     #include <stdio.h>
  1663.  
  1664.     char *fgets(char *buf, int n, FILE *fp)
  1665.  
  1666.     Get a string (maximum n characters) from file `fp' to 
  1667. buffer `buf'.
  1668.     Returns NULL if an error occurred or no characters were 
  1669. read,
  1670.     otherwise returns the (null-terminated) string.
  1671.  
  1672.     Example
  1673.  
  1674.     #include <io.h>
  1675.     #include <stdio.h>
  1676.  
  1677.     void main()
  1678.     {
  1679.         FILE *fp;
  1680.         char buffer[100];
  1681.  
  1682.         fp = fopen ("tfile", "r");
  1683.  
  1684.         while ( !feof(fp) )
  1685.         fgets(buffer, 100, fp);
  1686.  
  1687.         return;
  1688.     }
  1689.  
  1690.  
  1691.  
  1692. fopen
  1693.  
  1694.     #include <stdio.h>
  1695.  
  1696.     FILE *fopen(char *name, char *mode)
  1697.  
  1698.     Open a file with filename `name' returning a pointer to 
  1699. FILE.
  1700.     The following modes are allowed;
  1701.         `r'    open file for reading only
  1702.         `w'    open file for writing
  1703.         `a'    open file for append; position at end of file
  1704.  
  1705.         `r+'    open file for reading and writing
  1706.         `a+' `w+' create new file for reading and writing
  1707.  
  1708.  
  1709.     Example
  1710.  
  1711.     #include <io.h>
  1712.     #include <stdio.h>
  1713.  
  1714.     void main()
  1715.     {
  1716.         FILE *fp;
  1717.         if((fp = fopen("tfile","r"))==NULL) {
  1718.             printf("failed to open file tfile\n");
  1719.             return;
  1720.         }
  1721.         else {
  1722.                 fclose(fp);
  1723.                 printf("closed file tfile\n");
  1724.             }
  1725.         return;
  1726.     }
  1727.  
  1728.  
  1729.  
  1730. fprintf
  1731.  
  1732.     #include <stdio.h>
  1733.  
  1734.     int fprintf(FILE *fp, char *fmt, ...)
  1735.  
  1736.     Print formatted values to file. Arguments follow the 
  1737. format string and are interpreted
  1738.     according to the format string.
  1739.     fprintf writes its characters to the file stream fp.
  1740.  
  1741.     The format string is a sequence of characters with 
  1742. embedded conversion commands.
  1743.     Characters at are not part of the conversion     command 
  1744. are output. Conversion commands
  1745.     are the same as for the printf function.
  1746.  
  1747.     fprintf returns the number of characters written.
  1748.  
  1749.     Example
  1750.  
  1751.     #include <io.h>
  1752.     #include <stdio.h>
  1753.  
  1754.     void main()
  1755.     {
  1756.         FILE *fp;
  1757.         char *msg = "number formats are: ";
  1758.         int n = 42;
  1759.         fp=fopen("con","w");
  1760.  
  1761.         fprintf(fp,"%sx: 0%x d: %d o: %o\n",msg,n,n,n,n);
  1762.         fclose(fp);
  1763.         return;
  1764.     }
  1765.  
  1766.  
  1767.  
  1768. fputc
  1769.  
  1770.     #include <stdio.h>
  1771.  
  1772.     int fputc(int c, FILE *fp)
  1773.  
  1774.     Write a character c to file fp. Returns the character 
  1775. written.
  1776.  
  1777.     Example
  1778.  
  1779.     #include <io.h>
  1780.     #include <stdio.h>
  1781.  
  1782.     void main()
  1783.     {
  1784.         FILE *fp;
  1785.         char *buffer = "this text is written to console";
  1786.         fp=fopen("con","w");
  1787.  
  1788.         while(*buffer)
  1789.             fputc(*buffer++, fp);
  1790.         fclose(fp);
  1791.         return;
  1792.     }
  1793.  
  1794.  
  1795.  
  1796. fputs
  1797.  
  1798.     #include <stdio.h>
  1799.  
  1800.     int fputs(char *str, FILE *fp)
  1801.  
  1802.     Write a string str to file stream fp.
  1803.     Returns non-negative if successful, EOF if error 
  1804. occurred.
  1805.  
  1806.     Example
  1807.  
  1808.     #include <io.h>
  1809.     #include <stdio.h>
  1810.  
  1811.     void main()
  1812.     {
  1813.         FILE *fp;
  1814.         char *buffer = "this text is written to console";
  1815.         fp=fopen("con","w");
  1816.         fputs(buffer,fp);
  1817.         fclose(fp);
  1818.         return;
  1819.     }
  1820.  
  1821.  
  1822. fread
  1823.  
  1824.     #include <stdio.h>
  1825.  
  1826.     int fread(void *buf, int sizelem, int n, FILE *fp);
  1827.  
  1828.     Read `n' items, each of size `sizelem' from file `fp' 
  1829. into buffer `buf'.
  1830.     Returns the number of complete elements read.
  1831.  
  1832.     Example
  1833.  
  1834.     #include <io.h>
  1835.     #include <stdio.h>
  1836.     #include <system.h>
  1837.  
  1838.     void main()
  1839.     {
  1840.         FILE *fp;
  1841.         char *dest;
  1842.         int n;
  1843.  
  1844.         if((fp = fopen("tfile","r")) == NULL) return;
  1845.         dest = calloc(81,1);
  1846.         n = fread(dest,1,80,fp);
  1847.         printf("read %d bytes\n%s",n,dest);
  1848.         return;
  1849.     }
  1850.  
  1851.  
  1852.  
  1853. free
  1854.  
  1855.     #include <system.h>
  1856.  
  1857.     void free(void *ptr)
  1858.  
  1859.     Free memory block pointed to by `ptr'. The memory block 
  1860. described by ptr must have been
  1861.     allocated by calloc, malloc or realloc.
  1862.  
  1863.     Example
  1864.  
  1865.     #include <stdio.h>
  1866.     #include <system.h>
  1867.  
  1868.     void main()
  1869.     {
  1870.         char *p;
  1871.         if((p = malloc(100)) == NULL) {
  1872.           printf("out of memory\n");
  1873.           return; }
  1874.         free(p);
  1875.         return;
  1876.     }
  1877.  
  1878.  
  1879.  
  1880. fscanf
  1881.  
  1882.     #include <stdio.h>
  1883.  
  1884.     int fscanf(FILE *fp, char *format,...);
  1885.  
  1886.     Read characters from file `fp' and convert according to 
  1887. format string `format', storing via
  1888.     argument pointers which follow `format'.
  1889.     See the description of`scanf' for input format 
  1890. specification.
  1891.  
  1892.     Returns the number of arguments read from input.
  1893.  
  1894.     Example
  1895.  
  1896.     #include <stdio.h>
  1897.     #include <system.h>
  1898.  
  1899.     void main()
  1900.     {
  1901.         FILE *fp;
  1902.         char fst[10], sec[20];
  1903.         int n;
  1904.  
  1905.         fp=fopen("con","r");
  1906.         fscanf(fp, "%s %s %d",fst,sec,&n);
  1907.         printf("You typed %s %s %d\n",fst,sec,n);
  1908.         return;
  1909.     }
  1910.  
  1911.  
  1912.  
  1913. fwrite
  1914.  
  1915.     #include <stdio.h>
  1916.  
  1917.     int fwrite(void *buffer,int sizelem, int n,FILE *fp);
  1918.  
  1919.     Write `n' items, each of size `sizelem' to file `fp' from
  1920.     buffer `buf'.
  1921.  
  1922.     Returns the number of complete elements written.
  1923.  
  1924.  
  1925.  
  1926. getc
  1927.  
  1928.     #include <stdio.h>
  1929.  
  1930.     int getc(char *fp)
  1931.  
  1932.     Get a single character from file `fp'. Returns the 
  1933. character, or EOF if input error.
  1934.  
  1935.     Example
  1936.  
  1937.     #include <stdio.h>
  1938.  
  1939.     void main()
  1940.     {
  1941.         int n;
  1942.         FILE *fp;
  1943.  
  1944.         fp = fopen ("tfile", "r");
  1945.  
  1946.          while ( !feof(fp) )
  1947.         putchar(getc(fp));
  1948.  
  1949.         return;
  1950.     }
  1951.  
  1952.  
  1953.  
  1954. getchar
  1955.  
  1956.     #include <stdio.h>
  1957.  
  1958.     int getchar()
  1959.  
  1960.     Get a single character from stdin. Returns the character, 
  1961. or EOF if input error.
  1962.  
  1963.     Example
  1964.  
  1965.     #include <stdio.h>
  1966.  
  1967.     void main()
  1968.     {
  1969.         int n;
  1970.         FILE *fp;
  1971.  
  1972.          while ((n=getchar())!=EOF)
  1973.         putchar(n);
  1974.  
  1975.         return;
  1976.     }
  1977.  
  1978.  
  1979.  
  1980. gets
  1981.  
  1982.     #include <stdio.h>
  1983.  
  1984.     char *gets(char *buf)
  1985.  
  1986.     Get string from stdin into buffer `buf'. Reads characters 
  1987. from file until newline or end-of-
  1988.     file. The string written to `buf' is null-terminated.
  1989.  
  1990.     If a string was read into the buffer it's returned, else 
  1991. returns NULL.
  1992.  
  1993.     Example
  1994.  
  1995.     #include <stdio.h>
  1996.  
  1997.     void main()
  1998.     {
  1999.         char buf[80];
  2000.         gets(buf); puts(buf);
  2001.         return;
  2002.     }
  2003.  
  2004.  
  2005.  
  2006. is-ctype
  2007.  
  2008.     #include <ctype.h>
  2009.  
  2010.     int isxx(char c)
  2011.  
  2012.     Test a character to see if it's of a specified type.
  2013.     If it is, a non-zero value is returned; if not, zero is 
  2014. returned.
  2015.  
  2016.  
  2017.         isalnum        alphanumeric, letter or digit
  2018.         isalpha        alpha, letter
  2019.         isascii        ascii, 0-127
  2020.         iscntrl        control character
  2021.         isdigit        digit
  2022.         isgraph        graphic, printable
  2023.         islower        lowercase letter
  2024.         isprint        printable
  2025.         ispunct        punctuation
  2026.         isspace        space character
  2027.         isupper        uppercase letter
  2028.         isxdigit        hex digit
  2029.  
  2030.  
  2031.  
  2032. malloc
  2033.  
  2034.     #include <system.h>
  2035.  
  2036.     void *malloc(int n)
  2037.  
  2038.     Allocate buffer of n bytes from the heap,
  2039.     Returns address of buffer, or NULL if no memory 
  2040. available.
  2041.  
  2042.     Example
  2043.  
  2044.     #include <stdio.h>
  2045.     #include <system.h>
  2046.  
  2047.     void main()
  2048.     {
  2049.         char *p;
  2050.         if((p = malloc(100)) == NULL) {
  2051.           printf("out of memory\n");
  2052.           return; }
  2053.         free(p);
  2054.         return;
  2055.     }
  2056.  
  2057.  
  2058.  
  2059. memchr
  2060.  
  2061.     #include <string.h>
  2062.  
  2063.     void *memchr(void *buf, int c, int count);
  2064.  
  2065.     Search buffer `buf' for a character `c'. The search stops 
  2066. when a character `c' is found, or
  2067.     after `count' bytes.
  2068.  
  2069.  
  2070.  
  2071. memcmp
  2072.  
  2073.     #include <string.h>
  2074.  
  2075.     int memcmp(void *buf1, void *buf2, int n);
  2076.  
  2077.     Compare data in buffers `buf1' and `buf2', of size `n'.
  2078.  
  2079.     Returns        = 0    buf1 and buf2 hold identical data
  2080.             < 0    first differing byte in buf1 < buf2
  2081.             > 0    first differing byte in buf1 > buf2
  2082.  
  2083.  
  2084.  
  2085. memcpy, memmove
  2086.  
  2087.     #include <string.h>
  2088.  
  2089.     void *memcpy(void *buf1, void *buf2, int count);
  2090.     void *memmove(void *buf1, void *buf2, int count);
  2091.  
  2092.     Copy `count' bytes from buffer `buf2' to buffer `buf1'.
  2093.     Returns `buf1'.
  2094.  
  2095.  
  2096.  
  2097. memset
  2098.  
  2099.     #include <string.h>
  2100.  
  2101.     void *memset(void *buf, int val, int n);
  2102.  
  2103.     Sets contents of buffer `buf' of size `n' to value `val'.
  2104.     Returns buffer `buf'.
  2105.  
  2106.  
  2107.  
  2108. open
  2109.  
  2110.     #include <io.h>
  2111.  
  2112.     int open(char *name, int mode)
  2113.  
  2114.     Open a disk file `name' using read/write mode `mode', 
  2115. which can be O_RDONLY,
  2116.     O_WRONLY, O_RDWR
  2117.     returns file handle for the opened file, or EOF if there 
  2118. was an error opening the file.
  2119.  
  2120.     The mode may be    0 read-only    O_RDONLY
  2121.                 1 write-only    O_WRONLY
  2122.                 2 read-write    O_RDWR
  2123.  
  2124.     Example
  2125.  
  2126.     #include <io.h>
  2127.     #include <stdio.h>
  2128.  
  2129.     void main()
  2130.     {
  2131.         int fd;
  2132.         if (EOF == (fd = open("tfile",O_RDWR))) {
  2133.             printf ("failed to open tfile");
  2134.         }
  2135.         return;
  2136.     }
  2137.  
  2138.  
  2139.  
  2140. printf
  2141.  
  2142.     #include <stdio.h>
  2143.  
  2144.     int printf(char *fmt, ...)
  2145.  
  2146.     Print formatted values to screen. Arguments follow the 
  2147. format string and are interpreted
  2148.     according to the format string.
  2149.     The format string is a sequence of characters with 
  2150. embedded conversion commands.
  2151.     Characters that are not part of the conversion command 
  2152. are output.
  2153.  
  2154.     printf returns the number of characters written.
  2155.  
  2156.     The format string can contain text values, or a format 
  2157. specification for arguments, one per
  2158.     argument, beginning with a `%' character, the type 
  2159. matching the argument's type;
  2160.  
  2161.     % (conversion-flag) (min-field-width) (precision) 
  2162. (operation)
  2163.  
  2164.     eg %-20s  %12.4d
  2165.  
  2166.     The conversion flag character can be one of
  2167.  
  2168.         -    left adjust
  2169.         +    force sign output
  2170.         0    pad with 0 instead of space
  2171.         (space)    produce sign `-' or space
  2172.  
  2173.     Minimum field width is the minimum number of characters 
  2174. output for the field; if fewer
  2175.     characters are available from the argument, pad 
  2176. characters (0 or space) are inserted.
  2177.  
  2178.     Precision is the minimum number of characters printed 
  2179. from a number, or the maximum
  2180.     number of characters printed from a string.
  2181.  
  2182.     Operation specifies the expected argument type and what 
  2183. will be output; the expected output
  2184.     type must match the type of the corresponding argument 
  2185. for output to be meaningful.
  2186.  
  2187.         `h'    short int
  2188.         `l'    long int
  2189.         `c'    character
  2190.         `d' `i'     integer
  2191.         `o'    octal integer
  2192.         `p'    pointer
  2193.         `x'    hexadecimal
  2194.         `s'    string
  2195.         `u'    unsigned
  2196.     
  2197.     The number of characters written is returned.
  2198.  
  2199.     Example
  2200.  
  2201.     #include <io.h>
  2202.     #include <stdio.h>
  2203.  
  2204.     void main()
  2205.     {
  2206.         char *msg = "number formats are: ";
  2207.         int n = 42;
  2208.  
  2209.         printf(fp,"%sx: 0%x d: %d o: %o\n",msg,n,n,n,n);
  2210.         return;
  2211.     }
  2212.  
  2213.  
  2214.  
  2215. putc
  2216.  
  2217.     #include <stdio.h>
  2218.  
  2219.     int putc(int c, FILE *fp)
  2220.  
  2221.     Write character `c' to file `fp'. Returns `c'.
  2222.  
  2223.  
  2224.  
  2225. putchar
  2226.  
  2227.     #include <stdio.h>
  2228.  
  2229.     int putchar(int c)
  2230.  
  2231.     Write character `c' to stdout. Returns `c'.
  2232.  
  2233.     Example
  2234.  
  2235.     #include <stdio.h>
  2236.  
  2237.     void main()
  2238.     {
  2239.         int n;
  2240.         FILE *fp;
  2241.  
  2242.         fp = fopen ("tfile", "r");
  2243.  
  2244.          while ( !feof(fp) )
  2245.         putchar(getc(fp));
  2246.  
  2247.         return;
  2248.     }
  2249.  
  2250.  
  2251.  
  2252. puts
  2253.  
  2254.     #include <stdio.h>
  2255.  
  2256.     int puts(char *str)
  2257.  
  2258.     Writes string `str' to stdout, then writes a newline 
  2259. character.
  2260.  
  2261.     Example
  2262.  
  2263.     #include <stdio.h>
  2264.  
  2265.     void main()
  2266.     {
  2267.         char buf[80];
  2268.         gets(buf); puts(buf);
  2269.         return;
  2270.     }
  2271.  
  2272.  
  2273.  
  2274. read
  2275.  
  2276.     #include <io.h>
  2277.  
  2278.     int read(int fd, void *buf, int n)
  2279.  
  2280.     Read `n' bytes from file given by file descriptor `fd' 
  2281. into buffer `buf'. Direct DOS read from
  2282.     file.
  2283.  
  2284.     Returns        -1  error
  2285.             0   end of file
  2286.             n   number of bytes read
  2287.  
  2288.     Example
  2289.  
  2290.         #include <io.h>
  2291.         #include <stdio.h>
  2292.  
  2293.         void main()
  2294.         {
  2295.             char buf[80];
  2296.             int fd;
  2297.             if (EOF == (fd = open("tfile",O_RDWR))) {
  2298.                 printf ("failed to open tfile");
  2299.             }
  2300.             read(fd,buf,80); puts(buf);
  2301.             return;
  2302.         }
  2303.  
  2304.  
  2305.  
  2306. scanf
  2307.  
  2308.     #include <stdio.h>
  2309.  
  2310.     int scanf(char *format,...);
  2311.  
  2312.     Read arguments from stdin. Parse it according to 
  2313. specification in `format' string, and assign
  2314.     input to arguments following the format string.
  2315.  
  2316.     The arguments following `format' must be pointers to 
  2317. objects where the input is to be stored,
  2318.     and must match the specification in the format string.
  2319.  
  2320.     Returns the number of arguments assigned to. If no 
  2321. arguments were assigned, an EOF is
  2322.     returned.
  2323.  
  2324.     The format string may contain;
  2325.  
  2326.         - space characters; skip whitespace characters in 
  2327. input.
  2328.  
  2329.         - any other characters (except %) which should match 
  2330. input
  2331.           (match a `%' character by specifying `%%')
  2332.  
  2333.         - input conversion specification
  2334.  
  2335.             % (size) conversion-char
  2336.  
  2337.     If the conversion specification is %*(size) c-char then 
  2338. the converted input is not
  2339.     stored and no argument is used.
  2340.  
  2341.     If `size' is specified then at most `size' characters are 
  2342. converted. Otherwise
  2343.     conversion stops when an invalid input character is read.
  2344.  
  2345.     The conversion character specifies the input object type 
  2346. and must match the type of
  2347.     argument pointer;
  2348.  
  2349.         `h'    short int
  2350.         `l'    long int
  2351.         `c'    character
  2352.         `d' `i' integer
  2353.         `x'    hexadecimal
  2354.         `s'    string
  2355.  
  2356.  
  2357.     Example
  2358.  
  2359.     #include <io.h>
  2360.     #include <stdio.h>
  2361.  
  2362.     void main()
  2363.     {
  2364.         unsigned n;
  2365.         printf("type a number: ");
  2366.         scanf("%i",&n);
  2367.         printf("number %d is %x hex",n,n);
  2368.         return;
  2369.     }
  2370.  
  2371.  
  2372.  
  2373. sprintf
  2374.  
  2375.     #include <stdio.h>
  2376.  
  2377.     int sprintf(char *buf, char *fmt, ...)
  2378.  
  2379.     Print formatted values to memory. Arguments follow the 
  2380. format string and are interpreted
  2381.     according to the format string.
  2382.  
  2383.     sprintf returns the number of characters written.
  2384.     See printf for description of format string.
  2385.  
  2386.  
  2387.  
  2388. sscanf
  2389.  
  2390.     #include <stdio.h>
  2391.  
  2392.     int sscanf(char *buf, char *fmt, ...)
  2393.  
  2394.     Parse string in buffer `buf' according to specification 
  2395. in `format' string, and assign input to
  2396.     arguments following the format string.
  2397.  
  2398.     The arguments following `format' must be pointers to 
  2399. objects where the input is to be stored,
  2400.     and must match the specification in the format string.
  2401.  
  2402.     Returns the number of arguments assigned to. If no 
  2403. arguments were assigned, an EOF is
  2404.     returned.
  2405.  
  2406.  
  2407.  
  2408. strcat
  2409.  
  2410.     #include <string.h>
  2411.  
  2412.     char *strcat(char *buf1,  char *buf2)
  2413.  
  2414.     Catenate null-terminated string in `buf2' to the string 
  2415. in buffer `buf1'. Returns `buf1'.
  2416.  
  2417.  
  2418.  
  2419. strchr
  2420.  
  2421.     #include <string.h>
  2422.  
  2423.     char *strchr(char *str, int c)
  2424.  
  2425.     Search string `str' for character `c', return first 
  2426. occurrence.
  2427.  
  2428.  
  2429.  
  2430. strcmp
  2431.  
  2432.     #include <string.h>
  2433.  
  2434.     int strcmp(char *str1, char *str2)
  2435.  
  2436.     Compare null-terminated strings `str1' and `str2'. If 
  2437. they are identical then return 0. If the
  2438.     first differing character in `str1' is greater than that 
  2439. in `str2' then return a positive value,
  2440.     else return a negative value.
  2441.  
  2442.  
  2443.  
  2444. strcpy
  2445.  
  2446.     #include <string.h>
  2447.  
  2448.     char *strcpy(char *buf1, char *buf2)
  2449.  
  2450.     Copy null-terminated string in `buf2' to buffer `buf1'.
  2451.  
  2452.  
  2453.  
  2454. strdup
  2455.  
  2456.     #include <string.h>
  2457.  
  2458.     char *strdup(char *str)
  2459.  
  2460.     Create copy of null-terminated string `str' in newly 
  2461. allocated buffer, and return the buffer.
  2462.  
  2463.  
  2464.  
  2465. strlen
  2466.  
  2467.     #include <string.h>
  2468.  
  2469.     int strlen(char *str)
  2470.  
  2471.     Return length of null-terminated string `str'.
  2472.  
  2473.  
  2474.  
  2475. strlwr
  2476.  
  2477.     #include <string.h>
  2478.  
  2479.     char *strlwr(char *str)
  2480.  
  2481.     Convert string `str' to lowercase and return it.
  2482.  
  2483.  
  2484.  
  2485. strncat
  2486.  
  2487.     #include <string.h>
  2488.  
  2489.     char *strncat(char *buf1, char *buf2, int n)
  2490.  
  2491.     Catenate null-terminated string in `buf2' to null-
  2492. terminated string in `buf1'. At most `n'
  2493.     bytes are catenated.
  2494.     Returns `buf1'.
  2495.  
  2496.  
  2497.  
  2498. strncmp
  2499.  
  2500.     #include <string.h>
  2501.  
  2502.     int strncmp(char *buf1, char *buf2, int n)
  2503.  
  2504.     Compare null-terminated strings `str1' and `str2'. The 
  2505. strings are compared for at most `n'
  2506.     characters. If they are identical then return 0. If the 
  2507. first differing character in `str1' is
  2508.     greater than that in `str2' then return a positive value, 
  2509. else return a negative value.
  2510.  
  2511.  
  2512.  
  2513. strncpy
  2514.  
  2515.     #include <string.h>
  2516.  
  2517.     char *strncpy(char *buf1, char *buf2, int n)
  2518.  
  2519.     Copy null-terminated string in buffer `buf2' to buffer 
  2520. `buf1'. Exactly `n' characters are
  2521.     copied. If `buf2' contains fewer than `n' characters, 
  2522. destination `buf1' is padded with nulls.
  2523.  
  2524.  
  2525.  
  2526. strnicmp
  2527.  
  2528.     #include <string.h>
  2529.  
  2530.     int strnicmp(char *buf1, char *buf2, int n)
  2531.  
  2532.     Compares `n' characters of strings `buf1' and `buf2', 
  2533. ignoring case.
  2534.  
  2535.     Returns        0    strings equal, ignoring case
  2536.             < 0    first differing character `buf1' < `buf2'
  2537.             > 0    first differing character `buf1' > `buf2'
  2538.  
  2539.  
  2540.  
  2541. strpbrk
  2542.  
  2543.     #include <string.h>
  2544.  
  2545.     char *strpbrk(char *str1, char *str2)
  2546.  
  2547.     Search string `str1' for a character occurring in string 
  2548. `str2', return first occurrence.
  2549.  
  2550.  
  2551.  
  2552. strrchr
  2553.  
  2554.     #include <string.h>
  2555.  
  2556.     char *strrchr(char *buf, int c)
  2557.  
  2558.     Search null-terminated string in buffer `buf' for 
  2559. character `c', returning pointer to last
  2560.     occurrence of `c' in `buf'.
  2561.  
  2562.  
  2563.  
  2564. strrev
  2565.  
  2566.     #include <string.h>
  2567.  
  2568.     char *strrev(char *str)
  2569.  
  2570.     Reverses the contents of string `str'. Returns `str'.
  2571.  
  2572.  
  2573.  
  2574. strspn
  2575.  
  2576.     #include <string.h>
  2577.  
  2578.     int strspn(char *str1, char *str2)
  2579.  
  2580.     Span string `str1' skipping any characters in string 
  2581. `str2'.
  2582.  
  2583.  
  2584.  
  2585. strupr
  2586.  
  2587.     #include <string.h>
  2588.  
  2589.     char *strupr(char *str)
  2590.  
  2591.     Convert string `str' to uppercase, and return uppercased 
  2592. string.
  2593.  
  2594.  
  2595.  
  2596. tolower, toupper
  2597.  
  2598.     #include <string.h>
  2599.  
  2600.     int tolower(int c)
  2601.     int toupper(int c)
  2602.  
  2603.     Convert character `c' to lower/upper case.
  2604.  
  2605.  
  2606.  
  2607. ungetc
  2608.  
  2609.     #include <stdio.h>
  2610.  
  2611.     int ungetc(int c, FILE *fp)
  2612.  
  2613.     Push character `c' back to input file `fp'. Only one 
  2614. character may be ungetc'd.
  2615.     Returns `c' if succeeded, else EOF.
  2616.  
  2617.     Example
  2618.  
  2619.     #include <io.h>
  2620.     #include <stdio.h>
  2621.     #include <ctype.h>
  2622.  
  2623.     void main()
  2624.     {
  2625.         FILE *fp;
  2626.         char c;
  2627.  
  2628.         fp = fopen("tfile","r");
  2629.         while((c = fgetc(fp)) != EOF)
  2630.             if(isspace(c))
  2631.               break;
  2632.             else
  2633.               putchar(c);
  2634.  
  2635.       ungetc(c,fp);
  2636.       fclose(fp);
  2637.       return;
  2638.     }
  2639.  
  2640.  
  2641.  
  2642. vsprintf
  2643.  
  2644.     #include <stdio.h>
  2645.  
  2646.     int vsprintf(char *buf, char *fmt, char *args)
  2647.  
  2648.     Prints the arguments pointed to by stack segment pointer 
  2649. `args' to output buffer `buf'.
  2650.     See printf for description of format string,
  2651.     Returns the number of characters written.
  2652.  
  2653.  
  2654.  
  2655. write
  2656.  
  2657.     #include <stdio.h>
  2658.  
  2659.     int write(int fd, void *buffer, int size);
  2660.  
  2661.     Write memory buffer of length `size' to file `fd'. This 
  2662. is a direct DOS write to file.
  2663.     Returns the number of characters written or -1 if error.
  2664.  
  2665.     Example
  2666.  
  2667.     #include <io.h>
  2668.     #include <stdio.h>
  2669.     #include <string.h>
  2670.  
  2671.     void main()
  2672.     {
  2673.         int n, fd;
  2674.         char *buf = "test data to be written";
  2675.  
  2676.         if((fd = open("tfile",O_WRONLY)) == -1)
  2677.             {
  2678.                 puts("failed to open file");
  2679.                 return;
  2680.             }
  2681.         n = write(fd,buf,strlen(buf));
  2682.         printf("%u bytes written\n",n);
  2683.         close(fd);
  2684.         return;
  2685.     }
  2686.